local skill = fk.CreateSkill{
  name = "tea__chenglie"
}
---@type TrigSkelSpec<TrigFunc>
local chenglie = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      local room = player.room
      local cards = player:getCardIds(Player.Equip)
      for _, id in ipairs(player:getCardIds(Player.Judge)) do
        table.insertIfNeed(cards, id)
      end
      if table.find(cards, function(id)
        return #table.filter(room:getOtherPlayers(player), function(p)
          return player:canMoveCardInBoardTo(p, id)
        end) > 0
      end) then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:askToUseActiveSkill(player, {
      skill_name = "#tea__chenglie_active",
      cancelable = true,
    })
  end,
}
skill:addEffect(fk.Damage, chenglie)
skill:addEffect(fk.Damaged, chenglie)
skill:addTest(function (room, me)
  local comp2 = room.players[2]
  FkTest.runInRoom(function()
    room:handleAddLoseSkills(me, skill.name)
  end)

  local card = room:printCard("zhuahuangfeidian", Card.Heart, 1)
  FkTest.setNextReplies(comp2, { "__cancel", "__cancel" })
  FkTest.setNextReplies(me, { "1", json.encode{
    card = { skill = nil, subcards = { card.id } },
    targets = { comp2.id }
  } })
  FkTest.runInRoom(function()
    room:useCard{
      from = me,
      tos = { me },
      card = card,
    }
    room:loseHp(comp2, 1, "game_rule")
    room:damage{
      from = comp2,
      to = me,
      damage = 1,
    }
  end)
end)
return skill